﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using NineSeas.Extensions;
using Orchard.Taxonomies.Services;

namespace NineSeas.Api
{
    [Authorize]
    public class CategoryController : ApiController
    {
        private readonly ITaxonomyService _taxonomyService;
        public CategoryController(ITaxonomyService taxonomyService)
        {
            _taxonomyService = taxonomyService;
        }

        public IDictionary<string, CategoryViewModel> Get()
        {
            var taxonomy = _taxonomyService.GetTaxonomyByName(Constants.Taxonomies.Categories);
            return _taxonomyService.GetTerms(taxonomy.Id).ToDictionary(t => t.Id.ToString(), t => new CategoryViewModel {
                Id = t.Id.ToString(),
                Name = t.Name
            });
        }

        public class CategoryViewModel
        {
            public string Id { get; set; }
            public string Name { get; set; }
        }
    }
}